package com.seal.tsms.other.controller;


import com.seal.tsms.base.dao.Pagination;
import com.seal.tsms.other.entity.Subject;
import com.seal.tsms.other.service.SubjectService;
import org.hibernate.transform.Transformers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by seal on 2016/3/20.
 */
@Controller("otherIndexController")
@RequestMapping("/other")
public class IndexController {

    private SubjectService subjectService;

    public SubjectService getSubjectService() {
        return subjectService;
    }

    @Autowired
    @Qualifier("subjectServiceImpl")
    public void setSubjectService(SubjectService subjectService) {
        this.subjectService = subjectService;
    }

    @RequestMapping("/index")
    public String index(ModelMap model){

        Pagination pagination=new Pagination();
        pagination.setIndex(1);
        pagination.setSize(6);
        Map condition=new HashMap();
        Map p=new HashMap();
        condition.put(Pagination.PARAMS,p);
        //condition.put(Pagination.RESULT_HQL,"query.studentRecord");
        pagination.setCondition(condition);
        //最新发布的6条
        condition.put(Pagination.RESULT_HQL,"query.subject_new");
        subjectService.browse(pagination);
        model.addAttribute("news",pagination.getResult());

        //最新回复的6条
        condition.put(Pagination.RESULT_HQL,"query.subject_new_reply");
        subjectService.browse(pagination);
        model.addAttribute("new_replies",pagination.getResult());

        //支持最多的6条
        condition.put(Pagination.RESULT_HQL,"query.subject_love");
        subjectService.browse(pagination);
        model.addAttribute("loves",pagination.getResult());

        //回复最多的6条
        condition.put(Pagination.RESULT_HQL,"query.subject_love_reply");
        subjectService.browse(pagination);
        model.addAttribute("replies",pagination.getResult());

        return "other/index";
    }
}
